unit CadastroPortador;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UFomCadastro, StdCtrls, Buttons, ExtCtrls, DB, DBTables, Mask,
  DBCtrls, DBClient, Provider, Menus, ComCtrls, Grids, DBGrids;

type
  TFCadastroPortador = class(TFormCadastro)
    Label14: TLabel;
    DBText1: TDBText;
    Label1: TLabel;
    DBENome: TDBEdit;
    QPortador: TQuery;
    DSPortador: TDataSource;
    DBCHBDescontado: TDBCheckBox;
    dbeCodRelatorio: TDBEdit;
    Label2: TLabel;
    QCadastroPORT_CODIGO: TIntegerField;
    QCadastroPORT_DESCRICAO: TStringField;
    QCadastroDATAMODIFICACAO: TDateTimeField;
    QCadastroUSUARIO: TStringField;
    QCadastroCODIGOOLD: TIntegerField;
    QCadastroPORT_DESCONTADO: TIntegerField;
    QCadastroPORT_COD_RELATORIO: TStringField;
    QCadastroUSUARIO_CADASTRO: TStringField;
    QCadastroUSUARIO_AUTERACAO: TStringField;
    QCadastroUSUARIO_EXCLUSAO: TStringField;
    QCadastroDATA_CADASTRO: TDateTimeField;
    QCadastroDATA_EXCLUSAO: TDateTimeField;
    QCadastroDATA_AUTERACAO: TDateTimeField;
    QCadastroEXCLUIDO: TStringField;
    QCadastroUSUARIO_RECUPERACAO: TStringField;
    QCadastroDATA_RECUPERACAO: TDateTimeField;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure BtnIncluirClick(Sender: TObject);
    procedure BtnEditarClick(Sender: TObject);
    procedure BtnExcluirClick(Sender: TObject);
    procedure BtnSalvarClick(Sender: TObject);
    procedure BtnConsutaClick(Sender: TObject);
    procedure QCadastroAfterInsert(DataSet: TDataSet);
    procedure QCadastroBeforePost(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FCadastroPortador: TFCadastroPortador;

implementation

uses UGeral, PesquisaPortador;

{$R *.dfm}

procedure TFCadastroPortador.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 FCadastroPortador:=nil;
  inherited;
end;

procedure TFCadastroPortador.FormCreate(Sender: TObject);
begin
  QCadastro.SQl.Clear;
  QCadastro.SQl.Add('SELECT * FROM PORTADOR');
 inherited;
end;

procedure TFCadastroPortador.BtnIncluirClick(Sender: TObject);
begin

  inherited;
  DBENome.SetFocus;

end;

procedure TFCadastroPortador.BtnEditarClick(Sender: TObject);
begin

  if DsCadastro.Dataset.IsEmpty then
   begin
    ShowMessage('Tabela esta vazia !');
    exit;
   end;

  inherited;
  DBENome.SetFocus;

end;

procedure TFCadastroPortador.BtnExcluirClick(Sender: TObject);
begin

  if MessageDlg('Deseja realmente excluir este Portador ? ',mtWarning,mbOKCancel,0) = 2 then
   exit;

  inherited;

end;

procedure TFCadastroPortador.BtnSalvarClick(Sender: TObject);
begin

  if DBENome.Text = '' then
  begin
   ShowMessage('Campo Nome tem que ser preenchido !');
   exit;
  end;

  inherited;
end;

procedure TFCadastroPortador.BtnConsutaClick(Sender: TObject);
begin
  inherited;
 Application.CreateForm(TFPesquisaPortador, FPesquisaPortador);
 FPesquisaPortador.Show;
 Self.Enabled:=False;
end;

procedure TFCadastroPortador.QCadastroAfterInsert(DataSet: TDataSet);
begin
  inherited;
  QCadastro.FieldByName('PORT_DESCONTADO').AsVariant:=0;
end;

procedure TFCadastroPortador.QCadastroBeforePost(DataSet: TDataSet);
begin
  inherited;
  DataSet.FieldByName('USUARIO').AsString:=Usuario;
  DataSet.FieldByName('DATAMODIFICACAO').AsDateTime:=Date;
end;

end.
